home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 001-100 / 001-025 / 009 / proff / dostuff2.c < prev    next >
C/C++ Source or Header  |  1995-03-17  |  3KB  |  172 lines

  1.  
  2.  
  3.  
  4.  
  5. #include <stdio.h>
  6. #include <ctype.h>
  7. #include "proff.h"
  8. #include "debug.h"
  9.  
  10. /*
  11.  * dodef - define a command macro (".de xx" is in buf.)
  12.  *
  13.  */
  14. dodef(buf,fd)
  15. char buf[];
  16. int fd;
  17. {
  18.     char name[MAXNAME],defn[MAXDEF];
  19.     int i,junk;
  20.  
  21.     dprintf("dodef  ");
  22.     i = 0;
  23.     junk = getwrd(buf, &i, name);
  24.     i = getwrd(buf, &i, name);    /* get the name */
  25.     if (i == 0)
  26.         error("missing name in command def.");
  27.     i = 0;
  28.     while (ngetln(buf,fd) != NULL) {
  29.         if (buf[0] == cchar && buf[1] == 'e' &&
  30.             buf[2] == 'n' && !isalnum(buf[3]))
  31.             break;
  32.         junk = addstr(buf, defn, &i, MAXDEF);
  33.     }
  34.     if (addset(EOS, defn, &i, MAXDEF) == NO)
  35.         error("definition too long.\n");
  36.     if (install(name, defn, macrotab) == NULL)
  37.         fprintf(stderr,"no room for new definition.\n");
  38. #ifdef DEBUG
  39.     printf("dodef: %s (name) %s (defn)\n",name,defn);
  40. #endif
  41. }
  42.  
  43. /*
  44.  * doesc - expand escapes in buf
  45.  *
  46.  */
  47. doesc(buf, tbuf, size)
  48. char buf[];
  49. char tbuf[];
  50. int size;
  51. {
  52.     int i,j;
  53.  
  54.     dprintf("doesc  ");
  55.     j = 0;
  56.     for (i = 0; buf[i] != EOS && j < size-1; i++)
  57.         /*
  58.          * clean up generic escapes along the way.
  59.          */
  60.         if (buf[i] == genesc)
  61.             tbuf[j++] = buf[++i];
  62.  
  63.         else if (buf[i] != ESCAPE) {
  64.             tbuf[j] = buf[i];
  65.             j++;
  66.         }
  67.         else if (buf[i+1] == 'n' &&
  68.             (buf[i+2] >= 'a' && buf[i+2] <= 'z')) {
  69.             j += itoc(nr[buf[i+2] - 'a'],
  70.             &tbuf[j], size - j - 1);
  71.             i += 2;
  72.         }
  73.         else {
  74.             tbuf[j] = buf[i];
  75.             j++;
  76.         }
  77.     tbuf[j] = EOS;
  78.     strcpy(buf, tbuf);
  79. }
  80.  
  81. /*
  82.  * dovar - expand variables in buf
  83.  *
  84.  */
  85. dovar(tbuf, buf)
  86. char *buf;
  87. char *tbuf;
  88. {
  89.     register char *c, *p, t;
  90.     struct hashlist *xp;
  91.  
  92.     while (*buf != '\0') {
  93.         if (*buf == genesc) {
  94.             *tbuf++ = *buf++;
  95.             *tbuf++ = *buf;
  96.         }
  97.         else if (*buf != VESCAPE)
  98.             *tbuf++ = *buf;
  99.         else {
  100.             buf++;     /* skip the ESCAPE */
  101.             if (*buf == '{')
  102.                 buf++;
  103.             p = buf; /* save the beginning address of variable */
  104.             while (isalnum(*buf))
  105.                 buf++;
  106.             t = *buf;    /* save the character*/
  107.             *buf = '\0';    /* hack a null there */
  108.             if ((xp = lookup(p,gentab)) != NULL) {
  109.                 c = xp->def;    /* point to def */
  110.                 while (*c != '\0')
  111.                     *tbuf++ = *c++;
  112.             }
  113.             if (*(p-1) != '{')
  114.                 *tbuf++ = t;
  115.             else if (t != '}')
  116.                 fprintf(stderr, "missing \"}\" in %s\n",p);
  117.         }
  118.         buf++;
  119.     }
  120.     *tbuf = '\0';
  121. }
  122.  
  123.  
  124. /*
  125.  * dotabs - expand tabs in buf
  126.  *
  127.  */
  128. dotabs(buf,tbuf,size)
  129. char buf[];
  130. char tbuf[];
  131. int size;
  132. {
  133.     int i,j;
  134.     dprintf("dotabs  ");
  135.  
  136.     j = 0;
  137.     for (i = 0; buf[i] != EOS && j < size - 1; i++)
  138.         if (buf[i] == '\t')
  139.             while (j < size - 1) {
  140.                 tbuf[j] = ' ';
  141.                 j++;
  142.                 if (tabs[j] == YES || j > INSIZE)
  143.                     break;
  144.             }
  145.         else {
  146.             tbuf[j] = buf[i];
  147.             j++;
  148.         }
  149.     tbuf[j] = EOS;
  150.     strcpy(buf, tbuf);
  151. }
  152.  
  153. /*
  154.  * docline - produce a "contents" line.
  155.  *
  156.  */
  157. docline(str,width,cline,page)
  158. char *str;
  159. int width;
  160. char *cline;
  161. int page;
  162. {
  163.     int i;
  164.  
  165.     for (i = 0; i < width - 6 && cline[i] != '\0'; i++)
  166.         str[i] = cline[i];
  167.     while (i < width - 6)
  168.         str[i++] = '.';
  169.     sprintf(str+i,"%5d\n",page);
  170. }
  171.  
  172.